package cn.cvs.test;

import cn.cvs.dao.SysUserMapper;
import cn.cvs.pojo.SysUser;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.ibatis.session.defaults.DefaultSqlSession;
import org.apache.log4j.Logger;

import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * @author Jane
 * @date 2024-01-17 14:53
 */

public class Ch01_Count {
    static Logger logger=Logger.getLogger(Ch01_Count.class);
    public static void main(String[] args) throws IOException {

        //1. 加载mybatis_config.xml映射文件
        String url ="mybatis_config.xml";
        InputStream is = Resources.getResourceAsStream(url);

        //sqlSession 数据库连接的 会话
        //使用简单工厂的方式,去获取session
        SqlSession session =null;
        //Builder ->产生session工厂
        SqlSessionFactory fac= new SqlSessionFactoryBuilder().build(is);
        //开启
        session =fac.openSession();// 一个连接给多个人用

        //CRUD 增删改查
       // int count  = session.getMapper(SysUserMapper.class).getCount();
        //cn.cvs.dao.SysUserMapper.getCount  包.包.包.接口.方法名
        int count  = session.selectOne("cn.cvs.dao.SysUserMapper.getCount");
        logger.debug(count);
        System.out.println("总数: "+count);

        //关闭
        session.close();

    }


}
